package com.ztf.shopping.web.servlet;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.ztf.shopping.bean.Order;
import com.ztf.shopping.bean.User;
import com.ztf.shopping.service.UserService;
import com.ztf.shopping.service.imp.UserServiceImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAllShoppingCar")
public class FindAllShoppingCar extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        User user = (User) request.getSession().getAttribute("loginUser");
        UserService userService = new UserServiceImp();
        List<Order> orderList = userService.findAllShoppingCart(user.getName());
        ObjectMapper om = new ObjectMapper();
        om.writeValue(response.getOutputStream(),orderList);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
